home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Imaging / Create Image Document Icons < prev    next >
Encoding:
Text File  |  1999-03-04  |  5.5 KB  |  235 lines  |  [TEXT/ToyS]

  1. -- Properties
  2. property kasPrefName : "Image Icons V1.0"
  3.  
  4. property kasImgBox : {32, 0, 128, 128} -- Box of image
  5.  
  6. -- Globals
  7. global gasInfoWind -- Info window
  8. global gasInfoPos -- Position of info window
  9. global gasDrawing -- Draw window
  10. global gasDrawPos
  11.  
  12. global gasFoldersToDo -- The folders left to process
  13. global gasShown -- Number gone!
  14. global gasChecked -- Number checked!
  15.  
  16.  
  17. on open fsObjs
  18.     -- Load prefs, show window
  19.     pfLoad()
  20.     
  21.     -- Set up prefix
  22.     set gasShown to 0
  23.     set gasChecked to 0
  24.     set gasShowWind to 0
  25.     
  26.     set gasInfoWind to display info titled kasPrefName ¬
  27.         located at gasInfoPos ¬
  28.         message "Scanning…"
  29.     
  30.     set gasDrawing to ¬
  31.         display drawing titled ("Icon Creation") ¬
  32.             located at gasDrawPos ¬
  33.             with dimensions {128, 128}
  34.     
  35.     -- Do files
  36.     set gasFoldersToDo to {}
  37.     
  38.     repeat with fsObj in fsObjs
  39.         set myInfo to (basic info for fsObj)
  40.         
  41.         if (system type of myInfo is "fold") then
  42.             set gasFoldersToDo to gasFoldersToDo & {fsObj}
  43.         else
  44.             DoOne(fsObj)
  45.         end if
  46.     end repeat
  47.     
  48.     -- Do folders
  49.     repeat while gasFoldersToDo is not {}
  50.         -- Pop one off the end
  51.         set n to the number of items of gasFoldersToDo
  52.         set fsObj to item n of gasFoldersToDo
  53.         
  54.         if (n > 1) then
  55.             set gasFoldersToDo to items 1 through (n - 1) of gasFoldersToDo
  56.         else
  57.             set gasFoldersToDo to {}
  58.         end if
  59.         
  60.         display info gasInfoWind ¬
  61.             message ("Folders to go: " & n) ¬
  62.             at line 6 ¬
  63.             using color (15 * 32)
  64.         
  65.         -- Process it
  66.         GoDeep(fsObj)
  67.     end repeat
  68.     
  69.     display info gasInfoWind message "DONE!"
  70.     
  71.     pause for 2 with seconds timing -- Let screen wait...
  72.     
  73.     beep
  74.     
  75.     set gasInfoPos to screen location of ¬
  76.         (display info gasInfoWind with disposal)
  77.     
  78.     beep
  79.     
  80.     set gasDrawPos to screen location of ¬
  81.         (display info gasDrawing with disposal)
  82.     
  83.     beep
  84.     
  85.     pfSave() -- Save window location
  86. end open
  87.  
  88.  
  89. on DoOne(fsObj)
  90.     set imageType to the image type in fsObj
  91.     set fname to (catalog name of (basic info for fsObj))
  92.     
  93.     display info gasInfoWind ¬
  94.         message fname ¬
  95.         at line 2
  96.     
  97.     if (imageType is not "") then
  98.         display info gasInfoWind ¬
  99.             message imageType ¬
  100.             at line 3
  101.         -- Get picture
  102.         set imagePic to the image from fsObj
  103.         -- Get its bounds
  104.         set pBox to picture bounds of (the picture info for imagePic)
  105.         -- Center it
  106.         set drawInto to PlaceInCenter(pBox, kasImgBox)
  107.         -- Image BG
  108.         draw a box into gasDrawing ¬
  109.             inside of kasImgBox ¬
  110.             filling it with the pen ¬
  111.             using state {fg color:"EEEEEE"} ¬
  112.             with a clear slate
  113.         -- Draw image
  114.         -- draw a picture into gasDrawing ¬
  115.         --    inside of drawInto ¬
  116.         --    using data imagePic
  117.         -- Free image
  118.         set imagePic to 0
  119.         -- Draw Ear-lap
  120.         draw a box into gasDrawing ¬
  121.             inside of {96, 0, 128, 32} ¬
  122.             filling it by erasing it
  123.         draw a polygon into gasDrawing ¬
  124.             using data {{96, 0}, {96, 32}, {128, 32}} ¬
  125.             filling it with the pen ¬
  126.             using state {fg color:"CCCCCC", pen size:{3, 3}}
  127.         draw a polygon into gasDrawing ¬
  128.             using data {{96, 36}, {128, 36}} ¬
  129.             using state {fg color:"EEEEEE"}
  130.         draw a polygon into gasDrawing ¬
  131.             using data {{96, 0}, {96, 32}, {128, 32}} ¬
  132.             using state {fg color:"000000"}
  133.         -- Frame the image
  134.         draw a polygon into gasDrawing ¬
  135.             using data {{32, 0}, {96, 0}, {125, 32}, {125, 125}, {32, 125}, {32, 0}}
  136.         -- Draw text
  137.         draw a text box into gasDrawing ¬
  138.             inside of {4, 6, 34, 128} ¬
  139.             using data ("A" & return & "K" & return & "U" & return & "A") ¬
  140.             using state {text font:"Chicago", text size:24, text face:1, fg color:"5599FF"}
  141.         draw a text box into gasDrawing ¬
  142.             inside of {0, 2, 30, 124} ¬
  143.             using data ("A" & return & "K" & return & "U" & return & "A") ¬
  144.             using state {fg color:"224488"}
  145.         draw a text box into gasDrawing ¬
  146.             inside of {2, 4, 32, 126} ¬
  147.             using data ("A" & return & "K" & return & "U" & return & "A") ¬
  148.             with refresh
  149.         -- Get Picture / Assign Icon
  150.         set the icon of fsObj to (capture picture from gasDrawing with pixel conversion)
  151.         -- clip (capture picture from gasDrawing)
  152.     else
  153.         display info gasInfoWind ¬
  154.             message ¬
  155.             "Unknown" at line 3
  156.     end if
  157. end DoOne
  158.  
  159.  
  160. on GoDeep(foldObj)
  161.     display info gasInfoWind ¬
  162.         message "Path: " & (foldObj as string)
  163.     
  164.     set daddy to foldObj as string
  165.     
  166.     -- Do kinds that match
  167.     display info gasInfoWind ¬
  168.         message "Scanning files" at line 5
  169.     
  170.     set myItems to the entries in foldObj ¬
  171.         whose kinds are a file
  172.     
  173.     repeat with myItem in myItems
  174.         DoOne((daddy & myItem) as alias)
  175.     end repeat
  176.     
  177.     -- Do folders
  178.     display info gasInfoWind ¬
  179.         message "Scanning subfolders" at line 5
  180.     
  181.     set myItems to the entries in foldObj ¬
  182.         whose kinds are a folder
  183.     
  184.     repeat with myItem in myItems
  185.         set gasFoldersToDo to gasFoldersToDo & {(daddy & myItem) as alias}
  186.     end repeat
  187.     
  188.     -- Done
  189.     display info gasInfoWind ¬
  190.         message "…" at line 5
  191. end GoDeep
  192.  
  193.  
  194. on PlaceInCenter(src, dst)
  195.     set sW to (item 3 of src) - (item 1 of src)
  196.     set sH to (item 4 of src) - (item 2 of src)
  197.     set dW to (item 3 of dst) - (item 1 of dst)
  198.     set dH to (item 4 of dst) - (item 2 of dst)
  199.     
  200.     set r to dW / sW
  201.     set rH to dH / sH -- ratios
  202.     
  203.     if (rH < r) then set r to rH
  204.     
  205.     -- Round to a .25 ratio if > 1
  206.     if (r > 1) then ¬
  207.         set r to 0.25 * (round (r * 4))
  208.     
  209.     -- Scale the src
  210.     set sW to round (sW * r)
  211.     set sH to round (sH * r)
  212.     set mW to round ((dW - sW) / 2) + (item 1 of dst)
  213.     set mH to round ((dH - sH) / 2) + (item 2 of dst)
  214.     
  215.     -- Center it
  216.     return {mW, mH, mW + sW, mH + sH}
  217. end PlaceInCenter
  218.  
  219.  
  220. on pfLoad()
  221.     try
  222.         set ourPrefs to (load preference named kasPrefName)
  223.     on error
  224.         set ourPrefs to {{8, 48}, {8, 112}}
  225.     end try
  226.     
  227.     set gasInfoPos to item 1 of ourPrefs
  228.     set gasDrawPos to item 2 of ourPrefs
  229. end pfLoad
  230.  
  231.  
  232. on pfSave()
  233.     save preference {gasInfoPos, gasDrawPos} named kasPrefName
  234. end pfSave
  235.